package com.atstudy.controller;

import com.atstudy.entites.Account;
import com.atstudy.service.AccountService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.log4j.Log4j2;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2023/2/15 11:12
 * @copyright: 博为峰
 */
@Controller
@RequestMapping("/account")
@Slf4j
public class AccountController {

    @Autowired
    private AccountService accountService;

    @GetMapping(value = "/getAccountList")
    public String getAccountList(ModelMap map, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Account> accountList = accountService.getAccountList();
        PageInfo<Account> pageInfo = new PageInfo<>(accountList);
        map.addAttribute("pageInfo", pageInfo);
        return "account/account_list";
    }

    @GetMapping(value = "/getAccountListJson")
    @ResponseBody
    public PageInfo<Account> getAccountListJson(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Account> accountList = accountService.getAccountList();
        PageInfo<Account> pageInfo = new PageInfo<>(accountList);
        return pageInfo;
    }
}
